<template>
  <div>
    <breadcrumb>
      <span slot="first">首页</span>
      <span slot="second">订单管理</span>
      <span slot="third">订单列表</span>
    </breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="10">
          <el-input clearable placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table border :data="orderList">
        <el-table-column type="index">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格">
        </el-table-column>
        <el-table-column label="是否支付">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === 1">已支付</el-tag>
            <el-tag type="danger" v-else>未支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="addressUpadate"></el-button>
            <el-button size="mini" type="success" icon="el-icon-location" @click="progressClick"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog @close="addressDialogClosed" title="修改地址" :visible.sync="addressVisible" width="50%">
      <el-form :model="addressForm" :rules="addressRules" ref="addressRef"
        label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader class="cascader" :options="cityData"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流地址的对话框 -->
   
    <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">  <el-timeline :reverse="true">
      <el-timeline-item v-for="(item, index) in logistics" :key="index" :timestamp="item.time" color="#67c23a">
        {{item.content}}
      </el-timeline-item>
    </el-timeline>  
    </el-dialog>
  </div>
</template>

<script>
import Breadcrumb from '@/components/common/Breadcrumb.vue'
import { request } from '@/network/request'
import { formatDate } from '@/components/common/utils/formatDate'
import cityData from '@/components/common/utils/citydata'
import logistics from '@/components/content/orders/logistics'
export default {
  name: "Order",
  components: { Breadcrumb },
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      cityData,
      addressVisible: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressRules: {
        address1: [
          { required: true, message: '请选择省市县区', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ]
      },
      logistics,
      progressVisible: false
    }
  },
  methods: {
    async getOrderList() {
      // 获取商品数据
      const { data: res } = await request({
        url: 'orders',
        params: this.queryInfo
      })
      if (res.meta.status !== 200) return
      res.data.goods.forEach(item => {
        let date = new Date(item.create_time * 1000)
        item.create_time = formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      })
      this.total = res.data.total
      this.orderList = res.data.goods
      console.log(this.orderList);
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    addressUpadate() {
      this.addressVisible = true
    },
    addressDialogClosed() {
      this.$refs.addressRef.resetFields()
      this.addressForm.address1 = []
      this.addressForm.address2 = ''
    },
    progressClick() {
      this.progressVisible = true
    }
  },
  created() {
    this.getOrderList()
  },
}
</script>

<style lang='less' scoped>
.cascader {
  width: 100%;
}
</style>